package tank1;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * Version: 1.1
 * Author: TangJun
 * Date: 2024-07-30
 */
public class TankFrame extends JFrame{
    private final TankPanel tankPanel;
    public static final int WIDTH = 1920;
    public static final int HEIGHT = 1080;

    public static void main(String[] args) {
        new TankFrame();
    }
    public TankFrame() {
        tankPanel = new TankPanel();
        new Thread(tankPanel).start();//刷新界面
        this.add(tankPanel);//添加画板
        this.setTitle("坦克大战");
        this.addKeyListener(tankPanel);//添加键盘监听器到画板
        this.setSize(WIDTH, HEIGHT);//设置大小
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭指令
        this.setVisible(true);//设置是否可见
        //退出并保存
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                Recorder.Save();
                System.out.println("保存成功");
            }
        });
    }
}